﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StudyDefinitionLandingPage.xaml.cs" company="ELEN 7045 GROUP II">>
//   Contributed by E.Vosloo
// </copyright>
// <summary>
//   Interaction logic for StudyDefinitionLandingPage.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Presentation.Module.StudyDefinition
{
    #region

    using System.Windows;
    using System.Windows.Controls;

    using Microsoft.Practices.Prism.Regions;

    using Presentation.Module.StudyDefinition.Interfaces.Views;
    using Presentation.Shell.Interfaces;

    #endregion

    /// <summary>
    /// Interaction logic for StudyDefinitionLandingPage.xaml
    /// </summary>
    public partial class StudyDefinitionLandingPage : UserControl, IModuleLandingPage
    {
        #region Constants and Fields

        /// <summary>
        /// The LandingPageRegionName. In a production system this region would be stored in a configuration file
        /// </summary>
        private const string LandingPageRegionName = "MainRegion";

        /// <summary>
        /// The StudiesViewRegionName. In a production system this region would be stored in a configuration file
        /// </summary>
        private const string StudiesViewRegionName = "MainRegion";
        

        /// <summary>
        /// The SubjectGroupsViewRegionName. In a production system this region would be stored in a configuration file
        /// </summary>
        private const string SubjectGroupsViewRegionName = "MainRegion";
        

        /// <summary>
        /// The TreatmentsViewRegionName. In a production system this region would be stored in a configuration file
        /// </summary>
        private const string TreatmentsViewRegionName = "MainRegion";

        /// <summary>
        /// A Prism region manager instance.
        /// </summary>
        private readonly IRegionManager regionManagerInstance;

        /// <summary>
        /// A studies view instance.
        /// </summary>
        private readonly IStudiesView studiesViewInstance;

        /// <summary>
        /// A subject group view instance.
        /// </summary>
        private readonly ISubjectGroupsView subjectGroupsViewInstance;

        /// <summary>
        /// A treatments view instance.
        /// </summary>
        private readonly ITreatmentsView treatmentsViewInstance;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="StudyDefinitionLandingPage"/> class.
        /// </summary>
        /// <param name="regionManager">
        /// The region manager.
        /// </param>
        /// <param name="studiesView">
        /// The studies view dependency.
        /// </param>
        /// <param name="subjectGroupsView">
        /// The subject groups view dependency.
        /// </param>
        /// <param name="treatmentsView">
        /// The treatments view dependency.
        /// </param>
        public StudyDefinitionLandingPage(IRegionManager regionManager, IStudiesView studiesView, ISubjectGroupsView subjectGroupsView, ITreatmentsView treatmentsView)
        {
            InitializeComponent();

            // Get dependencies.
            this.regionManagerInstance = regionManager;

            this.studiesViewInstance = studiesView;
            this.subjectGroupsViewInstance = subjectGroupsView;
            this.treatmentsViewInstance = treatmentsView;

            // Add views to their respective regions.
            this.regionManagerInstance.Regions[StudiesViewRegionName].Add(this.studiesViewInstance);
            this.regionManagerInstance.Regions[SubjectGroupsViewRegionName].Add(this.subjectGroupsViewInstance);
            this.regionManagerInstance.Regions[TreatmentsViewRegionName].Add(this.treatmentsViewInstance);


            studiesViewInstance.ViewExit += ExitStudiesView;
            subjectGroupsViewInstance.ViewExit += ExitSubjectsView;
            treatmentsViewInstance.ViewExit += ExitTreatmentsView;

            this.studiesViewInstance = studiesView;
            this.subjectGroupsViewInstance = subjectGroupsView;
            this.treatmentsViewInstance = treatmentsView;
        }

        #endregion

        #region Events

        /// <summary>
        /// Occurs when [view exit].
        /// </summary>
        public event ViewExit ViewExit;

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets ParentView.
        /// </summary>
        public object ParentView { get; set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// Loads the studies view
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        public void LoadStudiesView(object sender, RoutedEventArgs e)
        {
            this.regionManagerInstance.Regions[StudiesViewRegionName].Activate(this.studiesViewInstance);
        }

        /// <summary>
        /// Loads the subject groups view
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        public void LoadSubjectGroupsView(object sender, RoutedEventArgs e)
        {
            this.regionManagerInstance.Regions[SubjectGroupsViewRegionName].Activate(this.subjectGroupsViewInstance);
        }

        /// <summary>
        /// Loads the treatments view
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        public void LoadTreatmentsView(object sender, RoutedEventArgs e)
        {
            this.regionManagerInstance.Regions[TreatmentsViewRegionName].Activate(this.treatmentsViewInstance);
        }

        #endregion

        #region Methods

        /// <summary>
        /// Cancels the specified sender.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.
        /// </param>
        private void Cancel(object sender, RoutedEventArgs e)
        {
            if (this.ViewExit != null)
            {
                this.ViewExit.Invoke();
            }
        }

        /// <summary>
        /// Exits the studies view.
        /// </summary>
        private void ExitStudiesView()
        {
            this.regionManagerInstance.Regions[LandingPageRegionName].Activate(this);
        }

        /// <summary>
        /// Exits the subjects view.
        /// </summary>
        private void ExitSubjectsView()
        {
            this.regionManagerInstance.Regions[LandingPageRegionName].Activate(this);
        }

        /// <summary>
        /// Exits the treatments view.
        /// </summary>
        private void ExitTreatmentsView()
        {
            this.regionManagerInstance.Regions[LandingPageRegionName].Activate(this);
        }

        #endregion
    }
}
